import Vue from 'vue'
import VueRouter from 'vue-router'


//前台路由
import home from "../views/home/home.vue"
import index from "../views/home/index.vue"
import login from "../views/home/login.vue"
import news from "../views/home/news.vue"
import store from "../views/home/store.vue" 
import register from "../views/home/register.vue"
import cart from "../views/home/cart.vue"
import getOrderInfo from "../views/home/getOrderInfo.vue"
import order from "../views/home/order.vue"




//后台路由
import admin from "../views/admin/admin.vue"



Vue.use(VueRouter)

const routes = [
    
//后台路由
    {
    path: "/adminlogin",
    name: "adminlogin",
    //懒加载
    component: ()=>import('@/views/admin/adminlogin')
    },

    {
        path:'/admin',
        component:admin,
        //守卫路由
        beforeEnter: (to, from, next) => {
           if(window.sessionStorage.getItem('adminid')){
            next();
           }else{
            next('/adminlogin')
           }
        },
        children:[{
            path: '/userlist',
            component: ()=>import('@/views/admin/user/userlist')
        },{
            path:'/storelist',
            component: ()=>import('@/views/admin/storelist')
        },{
            path:'/orderlist',
            component: ()=>import('@/views/admin/orderlist')
        }]
    },
  
    
//前台路由 

    { 
        path: '/',
        component: home,
        // redirect:'/index',
        children: [{
            path: '/login',
            component: login,
        },{
            path:'/news',
            component: news,
        },{
            path:'/store',
            component: store,
        },{
            path: '/index',
            component: index,
        },{
            path:'/register',
            component:register,
        },{
            path:'/cart',
            component:cart,
        },{
            path:'/getOrderInfo',
            component:getOrderInfo,
        },{
            path:'/order',
            component:order,
        }],

    }



]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

export default router